package com.contest.quartz.task;



import java.util.List;

import com.contest.quartz.QuartzManager;
import com.contest.quartz.data.ScheduleJob;
import org.junit.runner.RunWith;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


/**
 * 
* @Description: TODO()
* @ClassName: Test
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:application-context.xml"})
public class Test
{

	@org.junit.Test
	public void test2() throws Exception
	{
		ScheduleJob job = new ScheduleJob();
		job.setJobName("demo");
		job.setJobGroup("demo");
		job.setJobStatus(ScheduleJob.STATUS_RUNNING);
		//每一分三秒执行一次
		job.setDescription("demo");
		job.setBeanClass(TaskTest.class.getName());
		job.setMethodName("run");
		job.setSpringId("taskTest");
		job.setRunRuleComment("每5秒执行一次,共执行四次");
		job.getDataMap().put("name" , "xaoming");
		// 每5秒执行一次,共执行四次(注意参数为3)
		SimpleScheduleBuilder builder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5);//.withRepeatCount(3);
		QuartzManager.getInstance().addJob(job , builder);


		Thread.sleep(8000000);
		
	}
//	@org.junit.Test
	public void test1() throws Exception
	{
		ScheduleJob job = new ScheduleJob();
		job.setJobName("demo");
		job.setJobGroup("demo");
		job.setJobStatus(ScheduleJob.STATUS_RUNNING);
		//每一分三秒执行一次
		job.setCronExpression("3 */1 * * * ?");
		job.setDescription("demo");
		job.setBeanClass(TaskTest.class.getName());
		job.setMethodName("run");
		job.setSpringId("taskTest");
		job.getDataMap().put("name" , "xaoming");

		QuartzManager.getInstance().addJob(job);


		Thread.sleep(8000000);

	}

//	@org.junit.Test
	public void test() throws Exception
	{
		ScheduleJob job = new ScheduleJob();
		job.setJobName("demo");
		job.setJobGroup("demo");
		job.setJobStatus(ScheduleJob.STATUS_RUNNING);
		//每3秒执行一次
		job.setCronExpression("*/3 * * * * ?");
		job.setDescription("demo");
		job.setBeanClass(TaskTest.class.getName());
		job.setIsConcurrent(ScheduleJob.CONCURRENT_NOT);
		job.setMethodName("run");
		job.setSpringId("taskTest");

		QuartzManager.getInstance().addJob(job);


		job = new ScheduleJob();
		job.setJobName("test1");
		job.setJobGroup("demo");
		job.setJobStatus(ScheduleJob.STATUS_RUNNING);
		job.setCronExpression("*/3 * * * * ?");
		job.setDescription("test1");
		job.setBeanClass(TaskTest.class.getName());
		job.setIsConcurrent(ScheduleJob.CONCURRENT_NOT);
		job.setMethodName("run1");
		job.setSpringId("taskTest");

		QuartzManager.getInstance().addJob(job);

		List<ScheduleJob> list = QuartzManager.getInstance().getAllJob();
		System.out.println("job size:" + list.size());
		for(ScheduleJob sj : list)
		{
			System.out.println(sj.toString());
		}
		Thread.sleep(20000);
		QuartzManager.getInstance().pauseJob(job);
		System.out.println("pause job name:" + job.getJobName());
		Thread.sleep(50000);

	}


}
